import React, { useState } from 'react';
import {
  DesktopOutlined,
  FileOutlined,
  PieChartOutlined,
  TeamOutlined,
  UserOutlined,
} from '@ant-design/icons';
import { Breadcrumb, Layout, Menu, theme } from 'antd';
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
import { childrenList } from './router';

const { Header, Content, Footer, Sider } = Layout;

const App: React.FC = () => {

  const navigate=useNavigate()
  const {pathname}=useLocation()

  const erji=(arr, pathMach='')=>{
    
    return arr.map((item)=>{
      const furll=pathMach?`${pathMach}/${item.path}`:item.path
      return {
        key:furll,
        label:item.title,
        children:item.children?erji(item.children,furll):null
      }
    })
  }
  const items=erji(childrenList)
  


  const [collapsed, setCollapsed] = useState(false);
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();


  return (
    <div>
       <Layout style={{ minHeight: '100vh' }}>
      <Sider collapsible collapsed={collapsed} onCollapse={(value) => setCollapsed(value)}>
        <div className="demo-logo-vertical" />
        <Menu
        theme="dark" 
        defaultSelectedKeys={[pathname]} 
        onClick={(e)=>navigate(e.key)}
        mode="inline" 
        items={items} />
      </Sider>
      <Layout>
        <Header style={{ padding: 0, background: colorBgContainer }} />
        <Content style={{ margin: '0 16px' }}>
          <Breadcrumb style={{ margin: '16px 0' }} items={[{ title: 'User' }, { title: 'Bill' }]} />
          <div
            style={{
              padding: 24,
              minHeight: 360,
              background: colorBgContainer,
              borderRadius: borderRadiusLG,
            }}
          >
            <Outlet/>
          </div>
        </Content>
        <Footer style={{ textAlign: 'center' }}>
          Ant Design ©{new Date().getFullYear()} Created by Ant UED
        </Footer>
      </Layout>
    </Layout>
    </div>
  )
}

export default App
